package list;

public class SEList {
	int n;
	SEListNode dummy;

	/**
	 * Gets node and index in node for index i
	 * 
	 * @param i
	 * @return
	 */
	public Location getLocation(int i) {
		SEListNode u;
		if (i < n / 2) {
			u = dummy.next;
			while (i < u.d.size()) {
				i -= u.d.size();
			}
			return new Location(u, i);
		} else {
			int idx = n;
			u = dummy;
			while (idx > i) {
				u = u.prev;
				idx -= u.d.size();
			}
			return new Location(u, i - idx);

		}

	}
	public String get(int i){
		Location l=this.getLocation(i);
		return l.u.d.get(l.j);
	}
	
	public String set(String x, int i){
		Location l=this.getLocation(i);
		String y=l.u.d.set(l.j, x);
		return y;
	}

}
